/*
 * @Author: scopesang
 * @Date: 2022-03-16 09:32:55
 * @LastEditors: scopesang
 * @LastEditTime: 2022-03-17 09:54:23
 * @FilePath: \react-js-master\src\welcome.js
 * @Description:
 *
 * Copyright (c) 2022 by scopesang/大鹏科技, All Rights Reserved.
 */
import React from 'react'

class Welcome extends React.Component {
  // 第一天  state不能直接修改 只能通过setState 完成组件更新
  constructor(props) {
    super(props)
    this.state = {
      likes: 0
    }
    // 手动绑定
    // this.increaseLikes = this.increaseLikes.bind(this)
    // 另一种箭头函数
  }

  increaseLikes() {
    console.log(this) //js 的 class类中 是不会自动绑定this
    this.setState({
      likes: this.state.likes + 1
    })
  }

  render() {
    // const xiao = [1, 22, 3, 4];
    // const zhi = false
    return <button onClick={this.increaseLikes}>点赞{this.state.likes}</button>
  }
}

export default Welcome
